<template>
  <div class="market" >
    <el-tabs v-model="activeName" @tab-click="tab">
      <el-tab-pane v-for="item in menu" :label="item.label" :name="item.name">
      </el-tab-pane>
      <keep-alive>
        <router-view ></router-view>
      </keep-alive>
    </el-tabs>
  </div>
</template>
<script>
  import { isHasMenu } from '@/utils/m7Utils'
  import Marketing from './Marketing.vue'
  export default {
    name: 'market',
    data () {
      return {
        activeName: '',
        loading: false,
        currentRoute: '',
        activeComponent: '',
        menu: [
          {name: 'marketing', label: this.$t('market.marketing'), fun: 'func_marketing_diagnosis'}
//          {name: 'searchKeyword', label: this.$t('market.searchKeyword'), fun: 'func_marketing_searchKeyword'},
//          {name: 'customerAnalysis', label: this.$t('market.customerAnalysis'), fun: 'func_marketing_customerAnalysis'}
        ]
      }
    },
    components: {
      Marketing
    },
    methods: {
      isMenu (flag) {
//        过滤掉没有权限的列
        this.menu = this.menu.filter(item => {
          return !item.fun || (item.fun && isHasMenu(item.fun, this.$store.state.session.user))
        })
        if (!flag) {
//          默认展示第一项，如果有权限的话
          this.activeName = this.menu[0].name
          this.tab(this.menu[0])
        }
      },
      tab (tab) {
        // 如果是继续点击自己模块路由不跳转
        if (this.$route.path.indexOf(tab.name) !== -1) return
        this.$router.push({ path: '/index/market/' + tab.name })
      }
    },
    beforeRouteLeave (to, from, next) {
      this.currentRoute = from.fullPath
      next()
    },
    beforeRouteEnter (to, from, next) {
      next(vm => {
        if (vm.currentRoute) {
          vm.$router.push({path: vm.currentRoute})
        }
      })
    },
    beforeMount () {
      this.isMenu()
    }
  }
</script>
<style lang="stylus" scoped>
  .market
    background #fff
    height: 100vh
  .loading
    height: 100vh
  .el-tabs__item
    margin-left: 12px
</style>
